package com.shujia.utils;


import java.awt.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;

/*

        生成2万条语句
        insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (?,?,?,?,?,?,?,?);
 */
public class ExpandMysqlData {
    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement prep = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql://192.168.40.110:3306/bigdata17?useUnicode=true&characterEncoding=utf8&useSSL=false";
            String username = "root";
            String password = "123456";
            conn = DriverManager.getConnection(url, username, password);
//            System.out.println(conn);

//            String empno = "8001";

            prep = conn.prepareStatement("insert into emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) values (?,?,?,?,?,?,?,?)");

            String ename = "xiaohu";
            String job = "bigdata";
            String mgr = "xiaoge";
            String hiredate = "2022-05-17";
            String sal = "120000";
            String comm = "20000";
            String deptno = "20";

            long start = System.currentTimeMillis();
            for (int num = 28001; num <= 10000000; num++) {
                Integer num2 = new Integer(num);
                String s = num2.toString();
                prep.setString(1, s);
                prep.setString(2, ename + "-" + num);
                prep.setString(3, job + "-" + num);
                prep.setString(4, mgr + "-" + num);
                prep.setString(5, hiredate + "-" + num);
                prep.setString(6, sal + "-" + num);
                prep.setString(7, comm + "-" + num);
                prep.setString(8, deptno + "-" + num);
                prep.execute();
            }

            long end = System.currentTimeMillis();
            System.out.println("总耗时：" + (end - start));
            System.out.println("数据扩大完毕！！！");


        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (prep != null) {
                try {
                    prep.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }

    }

}
